<html>
<head><meta charset="utf-8"><title>Modifying the MIR of a function from rustc_driver · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Modifying.20the.20MIR.20of.20a.20function.20from.20rustc_driver.html">Modifying the MIR of a function from rustc_driver</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="225980717"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Modifying%20the%20MIR%20of%20a%20function%20from%20rustc_driver/near/225980717" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Modifying.20the.20MIR.20of.20a.20function.20from.20rustc_driver.html#225980717">(Feb 11 2021 at 12:06)</a>:</h4>
<p>Hi, is it possible to modify the MIR of a function from the <code>after_analysis</code> callback provided by rustc_driver?</p>



<a name="225983648"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Modifying%20the%20MIR%20of%20a%20function%20from%20rustc_driver/near/225983648" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Modifying.20the.20MIR.20of.20a.20function.20from.20rustc_driver.html#225983648">(Feb 11 2021 at 12:37)</a>:</h4>
<p>The only way to modify mir is by completely overriding the <code>optimized_mir</code> query provider. Why do you want to modify the MIR?</p>



<a name="225996872"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Modifying%20the%20MIR%20of%20a%20function%20from%20rustc_driver/near/225996872" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Modifying.20the.20MIR.20of.20a.20function.20from.20rustc_driver.html#225996872">(Feb 11 2021 at 14:20)</a>:</h4>
<p>I'd like to do some static analysis over the MIR that rustc does not do and then optimize stuff with the output of that analysis</p>



<a name="225996977"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Modifying%20the%20MIR%20of%20a%20function%20from%20rustc_driver/near/225996977" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Modifying.20the.20MIR.20of.20a.20function.20from.20rustc_driver.html#225996977">(Feb 11 2021 at 14:21)</a>:</h4>
<p>but I'd like to avoid having to maintain my own rustc for that</p>



<a name="225997214"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Modifying%20the%20MIR%20of%20a%20function%20from%20rustc_driver/near/225997214" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Modifying.20the.20MIR.20of.20a.20function.20from.20rustc_driver.html#225997214">(Feb 11 2021 at 14:23)</a>:</h4>
<p><code>rustc_interface::interface::Config</code> has a <code>override_queries</code> field. You will have to store the original <code>optimized_mir</code> query provider somewhere though I think to call it.</p>



<a name="226001348"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Modifying%20the%20MIR%20of%20a%20function%20from%20rustc_driver/near/226001348" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Modifying.20the.20MIR.20of.20a.20function.20from.20rustc_driver.html#226001348">(Feb 11 2021 at 14:51)</a>:</h4>
<blockquote>
<p>You will have to store the original optimized_mir query provider somewhere though I think to call it.</p>
</blockquote>
<p><a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/static.DEFAULT_QUERY_PROVIDERS.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/static.DEFAULT_QUERY_PROVIDERS.html</a></p>



<a name="226041903"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Modifying%20the%20MIR%20of%20a%20function%20from%20rustc_driver/near/226041903" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Modifying.20the.20MIR.20of.20a.20function.20from.20rustc_driver.html#226041903">(Feb 11 2021 at 19:08)</a>:</h4>
<p>does that mean that I would need to use the whole <code>rustc_interface</code> compiler session instead of the driver's Callbacks?</p>



<a name="226042712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Modifying%20the%20MIR%20of%20a%20function%20from%20rustc_driver/near/226042712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Modifying.20the.20MIR.20of.20a.20function.20from.20rustc_driver.html#226042712">(Feb 11 2021 at 19:13)</a>:</h4>
<p>I don't understand the question. This is just a normal lazy static that you can derefence to initialize it</p>



<a name="226124322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Modifying%20the%20MIR%20of%20a%20function%20from%20rustc_driver/near/226124322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Modifying.20the.20MIR.20of.20a.20function.20from.20rustc_driver.html#226124322">(Feb 12 2021 at 11:16)</a>:</h4>
<p>oh ok I think i get it now</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>